# author: wangs; date: 2023-02-02; dscript: arch docker config
FROM archlinux:latest

RUN echo '# install ---> archlinux-keyring' \
&& echo 'Server = https://mirrors.tuna.tsinghua.edu.cn/archlinux/$repo/os/$arch' > /etc/pacman.d/mirrorlist \
&& echo 'Server = https://mirrors.ustc.edu.cn/archlinux/$repo/os/$arch' >> /etc/pacman.d/mirrorlist \
&& pacman-key --init >/dev/null 2>&1 \
&& pacman-key --populate >/dev/null 2>&1\
&& pacman -Sy --noconfirm archlinux-keyring >/dev/null 2>&1

RUN echo '# install ---> archlinuxcn-keyring' \
&& echo -e '\n[archlinuxcn]' >> /etc/pacman.conf \
&& echo 'Include = /etc/pacman.d/archlinuxcn' >> /etc/pacman.conf \
&& echo 'Server = https://mirrors.tuna.tsinghua.edu.cn/archlinuxcn/$arch' > /etc/pacman.d/archlinuxcn \
&& echo 'Server = https://mirrors.ustc.edu.cn/archlinuxcn/$arch' >> /etc/pacman.d/archlinuxcn \
&& pacman -Sy --noconfirm archlinuxcn-keyring >/dev/null 2>&1

RUN echo '# install ---> base packages' \
&& pacman -Sy --noconfirm base base-devel net-tools bash-completion \
vi vim git wget curl zsh yay openssh wqy-microhei ttf-jetbrains-mono-nerd ttf-sourcecodepro-nerd \
xorg xorg-xinit xorg-apps xorg-server >/dev/null 2>&1

RUN echo '# user ---> modify root password; add user admin' \
&& echo -e 'root\nroot' | passwd root >/dev/null 2>&1 \
&& useradd -m -u 2001 -s /bin/zsh admin \
&& echo -e 'admin\nadmin' | passwd admin >/dev/null 2>&1 \
&& echo "admin   ALL=(ALL:ALL) ALL" >> /etc/sudoers

RUN echo '# config ---> ssh' \
&& ssh-keygen -A >/dev/null 2>&1 \
&& echo "PermitRootLogin yes" >> /etc/ssh/sshd_config

RUN echo '# config ---> oh-my-zsh' \
&& git clone https://gitee.com/mirrors/oh-my-zsh.git ~/.oh-my-zsh --depth=1 >/dev/null 2>&1 \
&& git clone https://gitee.com/ciwam/zsh-syntax-highlighting.git ~/.oh-my-zsh/plugins/zsh-syntax-highlighting --depth=1 >/dev/null 2>&1 \
&& git clone https://gitee.com/ciwam/zsh-autosuggestions.git ~/.oh-my-zsh/plugins/zsh-autosuggestions --depth=1 >/dev/null 2>&1

RUN echo '# config ---> zshrc' \
&& cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc \
&& echo '# zshrc plugs' >> ~/.zshrc \
&& echo 'source ~/.oh-my-zsh/plugins/cp/cp.plugin.zsh' >> ~/.zshrc \
&& echo 'source ~/.oh-my-zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh' >> ~/.zshrc \
&& echo 'source ~/.oh-my-zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh' >> ~/.zshrc \
&& echo 'autoload -Uz compinit && compinit' >> ~/.zshrc \
&& echo 'source ~/.oh-my-zsh/plugins/history/history.plugin.zsh' >> ~/.zshrc \
&& echo '#source ~/.oh-my-zsh/plugins/tmux/tmux.plugin.zsh' >> ~/.zshrc \
&& echo 'source ~/.oh-my-zsh/plugins/wd/wd.plugin.zsh' >> ~/.zshrc \
&& echo '#source ~/.oh-my-zsh/plugins/web-search/web-search.plugin.zsh' >> ~/.zshrc \
&& sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="jnrowe"/g' ~/.zshrc \
&& echo 'source /etc/profile' >> ~/.zshrc \
&& sudo sh -c 'chsh -s /bin/zsh' >/dev/null 2>&1

RUN echo '# config ---> git alias' \
&& echo '# git use' >> ~/.zshrc \
&& echo 'alias gst="git status -sb"' >> ~/.zshrc \
&& echo 'alias ga="git add"' >> ~/.zshrc \
&& echo 'alias gaa="git add -a"' >> ~/.zshrc \
&& echo 'alias gc="git commit"' >> ~/.zshrc \
&& echo 'alias gco="git checkout"' >> ~/.zshrc \
&& echo 'alias gcob="git checkout -b"' >> ~/.zshrc \
&& echo 'alias gl="git pull"' >> ~/.zshrc \
&& echo 'alias gp="git push"' >> ~/.zshrc \
&& echo 'alias glog="git log --graph --abbrev-commit --oneline"' >> ~/.zshrc

RUN echo '# install ---> vnc' \
&& yay -Sy --noconfirm tigervnc >/dev/null 2>&1 \
&& mkdir ~/.vnc && echo 'session=dwm' >> ~/.vnc/config \
&& mkdir -p /usr/share/xsessions \
&& echo '[Desktop Entry]' > /usr/share/xsessions/dwm.desktop \
&& echo 'Encoding=UTF-8' >> /usr/share/xsessions/dwm.desktop \
&& echo 'Name=Dwm' >> /usr/share/xsessions/dwm.desktop \
&& echo 'Comment=Dynamic window manager' >> /usr/share/xsessions/dwm.desktop \
&& echo 'Exec=dwm' >> /usr/share/xsessions/dwm.desktop \
&& echo 'Icon=dwm' >> /usr/share/xsessions/dwm.desktop \
&& echo 'Type=XSession' >> /usr/share/xsessions/dwm.desktop

RUN echo '# install/config ---> cc_dwm cc_st config' \
&& sudo chown admin:admin -R /opt && mkdir /opt/software && cd /opt/software \
&& git clone https://gitee.com/ciwam/cc_dwm.git /opt/software/cc_dwm >/dev/null 2>&1  \
&& cd /opt/software/cc_dwm && sudo make clean install >/dev/null 2>&1 \
&& git clone https://gitee.com/ciwam/cc_st.git /opt/software/cc_st >/dev/null 2>&1 \
&& cd /opt/software/cc_st && sudo make clean install >/dev/null 2>&1 \
&& git clone https://gitee.com/ciwam/config.git /opt/software/config >/dev/null 2>&1 \
&& ln -s /opt/software/config/scripts /opt/software \
&& ln -s /opt/software/config/wallpaper /opt/software \
&& sudo pacman -Sy --noconfirm feh >/dev/null 2>&1

RUN echo '# config ---> dev java' \
&& sudo mkdir /usr/local/jdk \
&& cd /usr/local/jdk \
&& sudo wget -c https://d6.injdk.cn/openjdk/zulu/8/zulu8.64.0.19-ca-jdk8.0.345-linux_x64.tar.gz >/dev/null 2>&1 \
&& cd /usr/local/jdk \
&& sudo tar xf zulu8.64.0.19-ca-jdk8.0.345-linux_x64.tar.gz \
&& sudo ln -s zulu8.64.0.19-ca-jdk8.0.345-linux_x64 latest \
&& sudo rm -f zulu8.64.0.19-ca-jdk8.0.345-linux_x64.tar.gz \
&& echo '## Java' >> /etc/profile \
&& echo 'JAVA_HOME=/usr/local/jdk/latest' >> /etc/profile \
&& echo 'JRE_HOME=/usr/local/jdk/latest/jre' >> /etc/profile \
&& echo 'CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib' >> /etc/profile \
&& echo 'PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin' >> /etc/profile \
&& echo 'export JAVA_HOME JRE_HOME CLASS_PATH PATH' >> /etc/profile \
&& source /etc/profile

RUN echo '# config ---> dev go' \
&& sudo mkdir /usr/local/go \
&& cd /usr/local/go \
&& sudo wget -c https://studygolang.com/dl/golang/go1.19.5.linux-amd64.tar.gz >/dev/null 2>&1 \
&& cd /usr/local/go \
&& sudo tar xf go1.19.5.linux-amd64.tar.gz \
&& sudo mv go go1.19.5 \
&& sudo ln -s go1.19.5 latest \
&& sudo rm -f go1.19.5.linux-amd64.tar.gz \
&& echo '## Golang' >> /etc/profile \
&& echo 'export GO111MODULE=on' >> /etc/profile \
&& echo 'export GOPROXY=https://goproxy.cn' >> /etc/profile \
&& echo 'export GOROOT=/usr/local/go/latest' >> /etc/profile \
&& echo 'export GOPATH=~/go' >> /etc/profile \
&& echo 'export GOBIN=~/go/bin' >> /etc/profile \
&& echo 'export PATH=$PATH:$GOROOT/bin' >> /etc/profile \
&& source /etc/profile

RUN echo '# config ---> dev python' \
&& pacman -Sy --noconfirm python3 python-pip >/dev/null 2>&1 \
&& mkdir ~/.pip \
&& echo '[global]' > ~/.pip/pip.conf \
&& echo 'index-url = https://pypi.douban.com/simple' >> ~/.pip/pip.conf

RUN echo '# clean ---> packages' \
&& pacman -Scc --noconfirm >/dev/null 2>&1

WORKDIR /root